package com.heima.article.controller.v1;

import com.heima.apis.article.ApArticleControllerApi;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.search.vo.SearchArticleVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {
    @Autowired
    private ApArticleService articleService;

    /**
     * 保存app文章
     * @param articleDto
     * @return
     */
    @PostMapping("/save")
    @Override
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto) {
        return articleService.saveArticle(articleDto);
    }

    @GetMapping("{id}")
    @Override
    public SearchArticleVo findArticle(@PathVariable Long id) {
        ApArticle article = articleService.getById(id);
        if(article!=null){
            SearchArticleVo searchArticleVo = new SearchArticleVo();
            BeanUtils.copyProperties(article,searchArticleVo);
            return searchArticleVo;
        }
        return null;
    }
}